package com.lingshi.shopping_manager_api.security;

import cn.dev33.satoken.stp.StpUtil;
import com.lingshi.shopping_common.exception.BusCodeEnum;
import com.lingshi.shopping_common.exception.BusException;
import com.lingshi.shopping_common.result.BaseResult;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

public class CheckLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  {
        //判断是否登录
        if(!StpUtil.isLogin()){
            //抛出逻辑异常，全局异常捕获
            throw new BusException(BusCodeEnum.NOT_LOGIN_ERROR);
        }

        return true;
    }
}
